<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    
    <title>facebook login</title>
    
<script id="facebook-jssdk" async="" src="http://connect.facebook.net/ko_KR/all.js"></script>
<script src="/resources/js/jquery-1.11.0.js"></script>
<script type="text/javascript">
	window.fbAsyncInit = function() {
		FB.init({appId: '1427921877464450', status: true, cookie: true,xfbml: true});
	};
	
	(function(d){
	     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
	     if (d.getElementById(id)) return;
	     js = d.createElement('script'); js.id = id; js.async = true;
	     js.src = "//connect.facebook.net/ko_KR/all.js";
	     ref.parentNode.insertBefore(js, ref);
	}(document));
	
	
	function init(){
		setTimeout(function(){
			FB.login(function(response) {
				if (response.status == 'connected') {
		        	FB.api('/me', function(user) {
		                if (user) {
		                	var data = 'fb_name='+user.name+'&fb_id='+user.id+'&fb_email='+user.email+'&fb_gender='+user.gender;
		                	alert(data);
		                	$.ajax({
		                		type : "POST"
		            		    , url : "/fb_getMember"
		            		    , data : data
		            		    , dataType : "text"
		            		    , timeout : 5000
		            		    , error : function(request, status, error) {
		            		    	alert("서버문제로 로그인할 수 없습니다");
		            		    }
		            		    , success : function(response) {
		            		    	alert(response);
		            		    	if(response == "login"){
		            		    		alert('d');
		            		    		window.close();
		            		    	}else if(response == "sign"){
		            		    		window.location = '/start_guide';
		            		    	}else{
		            		    		alert("로그인할 수 없습니다");
		            		    	}
		            		    }
		            		});
		                }else{
		                	alert("페이스북 로그인에 실패하였습니다");
		                }
		        	});
		        }else if (response.status == 'not_authorized') {
		        	alert("페이스북 로그인에 실패했습니다");
		        }else{
		        	alert("페이스북 로그인에 실패했습니다");
		        }
			}, {scope: 'email'});
		}, 1000);
	}
</script>
</head>
<body onload="init();">
<div id="fb-root"></div>
</body>
</html>